﻿<Table TItem="BindItem"
       IsPagination="true" PageItemsSource="@PageItemsSource"
       IsStriped="true" IsBordered="true"
       ShowToolbar="true" ShowDefaultButtons="false"
       OnQueryAsync="@OnQueryAsync">
    <TableColumns>
        <TableColumn @bind-Field="@context.DateTime" Width="180" />
        <TableColumn @bind-Field="@context.Name" Width="100" />
        <TableColumn @bind-Field="@context.Address" />
        <TableColumn @bind-Field="@context.Count" />
    </TableColumns>
    <DetailRowTemplate>
        @{
            var DetailDataSource = GetDetailRowsByName(context.Name ?? "");
        }
        <Table TItem="DetailRow" IsBordered="true" ShowToolbar="false" Items="@DetailDataSource">
            <TableColumns Context="Detail">
                <TableColumn @bind-Field="@Detail.Name" />
                <TableColumn @bind-Field="@Detail.DateTime" Width="180" />
                <TableColumn @bind-Field="@context.Complete" Width="70">
                    <Template Context="v">
                        <Switch IsDisabled="true" Value="v.Value" ShowInnerText="true" OnInnerText="是" OffInnerText="否" />
                    </Template>
                </TableColumn>
            </TableColumns>
        </Table>
    </DetailRowTemplate>
</Table>

@code {
    private IEnumerable<DetailRow> GetDetailRowsByName(string name) => Enumerable.Range(1, 4).Select(i => new DetailRow()
    {
        Id = i,
        Name = name,
        DateTime = DateTime.Now.AddDays(i - 1),
        Complete = random.Next(1, 100) > 50
    });

    private class DetailRow
    {
        [DisplayName("主键")]
        public int Id { get; set; }

        [DisplayName("培训课程")]
        public string Name { get; set; } = "";

        [DisplayName("日期")]
        public DateTime DateTime { get; set; }

        [DisplayName("是/否")]
        public bool Complete { get; set; }
    }
}